package com.wswy.wzcx.model.resp;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.wswy.wzcx.model.ICity;
import com.wswy.wzcx.model.WZCity;

import java.util.List;

public class ProvinceData implements ICity, Parcelable {

    @SerializedName("list")
    public List<WZCity> list;

    @SerializedName("name")
    public String name;

    @SerializedName("pid")
    public int pid;

    @SerializedName("nameCn")
    public String nameCn;

    public ProvinceData() {
    }

    protected ProvinceData(Parcel in) {
        list = in.createTypedArrayList(WZCity.CREATOR);
        name = in.readString();
        pid = in.readInt();
        nameCn = in.readString();
    }

    public static final Creator<ProvinceData> CREATOR = new Creator<ProvinceData>() {
        @Override
        public ProvinceData createFromParcel(Parcel in) {
            return new ProvinceData(in);
        }

        @Override
        public ProvinceData[] newArray(int size) {
            return new ProvinceData[size];
        }
    };

    @Override
    public String getCityName() {
        return name;
    }

    @Override
    public long getHeaderId() {
        initFirst();
        return firstLetterId;
    }

    @Override
    public String getNameLatter() {
        initFirst();

        return firstLetter;
    }

    private transient int firstLetterId;
    private transient String firstLetter;
    private void initFirst(){
        if (firstLetter == null && !TextUtils.isEmpty(nameCn)){
            firstLetter = String.valueOf(nameCn.charAt(0)).toUpperCase();
            firstLetterId = firstLetter.charAt(0);
        }
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(list);
        dest.writeString(name);
        dest.writeInt(pid);
        dest.writeString(nameCn);
    }
}